<script setup lang="ts">
import { PropType } from 'vue'
import { toLine } from '../../../utils'
import { ListOptions, ActionOptions, ListItem } from '../../../types/list/'
let props = defineProps({
  // 列表的内容
  list: {
    type: Array as PropType<ListOptions[]>,
    require: true
  },
  // 操作的内容
  actions: {
    type: Array as PropType<ActionOptions[]>,
    default: () => []
  }
})

let emits = defineEmits(['clickItem', 'clickAction'])

let clickItem = (item: ListItem, index: Number) => {
  emits('clickItem', { item, index })
}

let clickAction = (item: ActionOptions, index: Number) => {
  emits('clickAction', { item, index })
}

</script>
<template>
  <div class="list-tabs__item">
    <el-tabs >
      <el-scrollbar max-height="300px">
        <el-tab-pane :label="listItem.title" v-for="(listItem, listIndex) in list" :key="listIndex">
          <div class="container"
            @click="clickItem(conItem, conIndex)"
            v-for="(conItem, conIndex) in listItem.content"
            :key="conIndex">
              <div class="avatar" v-if="conItem.avatar">
                <el-avatar size="default" :src="conItem.avatar" />
              </div>
              <div class="content">
                <div v-if="conItem.title" class="title">
                  <div>{{conItem.title}}</div>
                  <el-tag :type="conItem.tagType" size="small" v-if="conItem.tag">{{conItem.tag}}</el-tag>
                </div>
                <div class="desc" v-if="conItem.desc">{{conItem.desc}}</div>
                <div class="time"  v-if="conItem.time">{{conItem.time}}</div>
              </div>
          </div>
          <div class="actions">
            <div class="actions-item" 
              @click="clickAction(actionItem, actionIndex)"
              :class="{ border: actionIndex !== actions.length - 1}"
              v-for="(actionItem, actionIndex) in actions"
              :key="actionIndex">
                <div class="actions-icon" v-if="actionItem.icon">
                  <component :is="`el-icon-${toLine(actionItem.icon)}`"></component>
                </div>
                <div class="actions-text">{{actionItem.text}}</div>
            </div>
          </div>
        </el-tab-pane>
      </el-scrollbar>
    </el-tabs>
  </div>
</template>
<style lang="scss" scoped>
.container{
  display: flex;
  align-items: center;
  padding: 12px 20px;
  cursor: pointer;
  &:hover{
    background-color: #e6f6ff;
  }
  .avatar{
    flex: 1;
  }
  .content{
    flex: 3;
    .title{
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    .desc,
    .time{
      font-size: 12px;
      color: #999;
      margin-top: 4px;
    }
  }
}
.actions{
  height: 50px;
  display: flex;
  align-items: center;
  border-top: 2px solid #eee;
  .actions-item{
    height: 50px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    .actions-icon{
      margin-right: 4px;
      position: relative;
      top: 2px;
    }
  }
}

.border{
  border-right: 1px solid #eee;
}
</style>